/*自定义--基础管理*/
import { routerRedux } from 'dva/router';
import * as LoginService from '../services/basics';

export default {
  namespace: 'manamenu',
  state: {
    data: [],
  },
  effects: {
  	/*菜单管理*/
    *fetch_menu({ payload }, { call, put }) {
      const response = yield call(LoginService.get,'/api/web/menu/slicedQueryMenu',payload); 
    	yield put({type: 'save',payload: response.data.obj,});
    },
    /*菜单管理tree 上级菜单*/
    *fetch_menu_tree({ payload, callback }, { call, put }) {
      const response = yield call(LoginService.get,'/api/web/menu/getMenuTreeList');
      callback(response.data.res,response.data.obj);
    },
    /*新增菜单*/
    *add_menu({ payload, callback }, { call, put }) {
      const response = yield call(LoginService.get,'/api/web/menu/insertMenu', payload);
     	yield put({type:'fetch_menu',});
    },
    /*编辑菜单*/
    *edit_menu({ payload, callback }, { call, put }) {
      const response = yield call(LoginService.get,'/api/web/menu/updateMenu', payload);
     	yield put({type:'fetch_menu',});
    },
    /*修改状态*/
    *edit_menu_state({ payload, callback }, { call, put }) {
      const response = yield call(LoginService.get,'/api/web/menu/updateMenuStates', payload);
     	yield put({type:'fetch_menu',});
    },
    /*删除菜单*/
    *remove_menu({ payload, callback }, { call, put }) {
      const response = yield call(LoginService.get,'/api/web/menu/deleteMenus', payload);
      yield put({type:'fetch_menu',});
    },
  },
  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload,
      };
    },
  },
};
